package com.cardone.platform.authority.controller;

import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;

import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cardone.context.Contexts;
import com.cardone.common.dto.PaginationDto;
import com.cardone.common.dto.ReturnDataDto;
import com.cardone.common.util.ReturnDataUtils;
import com.cardone.context.ContextHolder;
import com.cardone.platform.authority.dto.UsGroupRoleDto;
import com.cardone.platform.authority.service.UsGroupRoleService;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

/**
 * 用户组与角色
 *
 * @author yaohaitao
 */
@Deprecated
@Setter
@Slf4j
@RequestMapping("/authority/usGroupRole/")
@Controller
public class UsGroupRoleController {

	/**
	 * 用户组与角色：删除
	 * 
	 * @param deleteUsGroupRole
	 *            用户组与角色对象
	 * @return 处理结果，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "delete.json" }, method = RequestMethod.POST)
	@ResponseBody
  public Callable<ReturnDataDto<String>> deleteJson(final UsGroupRoleDto deleteUsGroupRole) {
		return new Callable<ReturnDataDto<String>>() {
			public ReturnDataDto<String> call() throws Exception {
				try {
					ContextHolder.getBean(UsGroupRoleService.class).deleteByIds(deleteUsGroupRole);
					
					return ReturnDataUtils.newReturnData();
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, log);
				}
			}
		};
	}

	/**
	 * 用户组与角色：编辑
	 * 
	 * @param findUsGroupRole
	 *            用户组与角色对象
	 * @return 实体对象集，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "findById.json" })
	@ResponseBody
	public Callable<ReturnDataDto<UsGroupRoleDto>> findByIdJson(final UsGroupRoleDto findUsGroupRole, final Model model) {
		return new Callable<ReturnDataDto<UsGroupRoleDto>>() {
			@Override
			public ReturnDataDto<UsGroupRoleDto> call() throws Exception {
				try {
					final UsGroupRoleDto usGroupRole = ContextHolder.getBean(UsGroupRoleService.class).findById(UsGroupRoleDto.class, findUsGroupRole);

					return ReturnDataUtils.newReturnData(usGroupRole);
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, UsGroupRoleController.log);
				}
			}
		};
	}

	/**
	 * 用户组与角色：分页查询
	 * 
	 * @param paginationUsGroupRole
	 *            用户组与角色对象
	 * @return 分页，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "paginationByLikeCode.json" })
	@ResponseBody
  public Callable<ReturnDataDto<PaginationDto<UsGroupRoleDto>>> paginationByLikeCodeJson(final UsGroupRoleDto paginationUsGroupRole) {
		return new Callable<ReturnDataDto<PaginationDto<UsGroupRoleDto>>>() {
			public ReturnDataDto<PaginationDto<UsGroupRoleDto>> call() throws Exception {
				try {
					final PaginationDto<UsGroupRoleDto> usGroupRolePagination = ContextHolder.getBean(UsGroupRoleService.class).paginationByLikeCode(UsGroupRoleDto.class, paginationUsGroupRole);
				
					return ReturnDataUtils.newReturnData(usGroupRolePagination);
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, log);
				}
			}
		};
	}

	/**
	 * 用户组与角色：分页查询
	 * 
	 * @param paginationUsGroupRole
	 *            用户组与角色对象
	 * @param model
	 *            上下文映射
	 */
	@Deprecated
	@RequestMapping(value = { "pagination.html" })
  public void paginationHtml(final UsGroupRoleDto paginationUsGroupRole, final Model model) {
		final PaginationDto<UsGroupRoleDto> usGroupRolePagination = ContextHolder.getBean(UsGroupRoleService.class).paginationByLikeCode(UsGroupRoleDto.class, paginationUsGroupRole);
		
		model.addAttribute("usGroupRolePagination", usGroupRolePagination);
	}
	
	/**
	 * 用户组与角色：分页查询
	 * 
	 * @param findUsGroupRole
	 *            用户组与角色对象
	 * @param model
	 *            上下文映射
	 */
	@Deprecated
	@RequestMapping(value = { "edit.html" })
  public void editHtml(final UsGroupRoleDto findUsGroupRole, final Model model) {
		final UsGroupRoleDto usGroupRole = ContextHolder.getBean(UsGroupRoleService.class).findById(UsGroupRoleDto.class, findUsGroupRole);
		
		model.addAttribute("usGroupRole", usGroupRole);
	}

	/**
	 * 用户组与角色：查询
	 * 
	 * @param findListUsGroupRole
	 *            用户组与角色对象
	 * @return 用户组与角色对象集合，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "findListByLikeCode.json" })
	@ResponseBody
  	public Callable<ReturnDataDto<List<UsGroupRoleDto>>> findListByLikeCodeJson(final UsGroupRoleDto findListUsGroupRole) {
		return new Callable<ReturnDataDto<List<UsGroupRoleDto>>>() {
			public ReturnDataDto<List<UsGroupRoleDto>> call() throws Exception {
				try {
					final List<UsGroupRoleDto> usGroupRoleList = ContextHolder.getBean(UsGroupRoleService.class).findListByLikeCode(UsGroupRoleDto.class, findListUsGroupRole);
				
					return ReturnDataUtils.newReturnData(usGroupRoleList);
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, log);
				}
			}
		};
	}

	/**
	 * 用户组与角色：保存
	 * 
	 * @param saveUsGroupRole
	 *            用户组与角色对象
	 * @return 处理结果，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "save.json" })
	@ResponseBody
  public Callable<ReturnDataDto<String>> saveJson(final UsGroupRoleDto saveUsGroupRole) {
		return new Callable<ReturnDataDto<String>>() {
			public ReturnDataDto<String> call() throws Exception {
				try {
					ContextHolder.getBean(UsGroupRoleService.class).saveByIdOrCode(UsGroupRoleDto.class, saveUsGroupRole);
					
					return ReturnDataUtils.newReturnData();
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, log);
				}
			}
		};
	}
}
